import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'lx_location_plugin_platform_interface.dart';

/// An implementation of [LxLocationPluginPlatform] that uses method channels.
class MethodChannelLxLocationPlugin extends LxLocationPluginPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('lx_location_plugin');

  final eventChannel = const EventChannel('lx_location_plugin/location_updates');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<String?> startLocationService() async {
    final result = await methodChannel.invokeMethod<String>('startLocationService');
    print("startLocationService result: $result");
    return result;
  }

  @override
  Future<String?> stopLocationService() async {
    final result = await methodChannel.invokeMethod<String>('stopLocationService');
    print("stopLocationService result: $result");
    return result;
  }

  @override
  Stream<Map<String, dynamic>> get locationUpdates {
    return eventChannel
        .receiveBroadcastStream()
        .map((dynamic event) => Map<String, dynamic>.from(event));
  }

}
